package com.dragon.mmochat.message;

import java.util.Map.Entry;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.battle.record.MmochatBattleRecord;
import com.dragon.mmochat.model.battle.record.MmochatRoleRecord;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_3_1S_Record extends SkymobiProtocolMessage {
	int mapId;
	byte line;
	byte myPos;
	Byte petPos = null;
	boolean isAudience = false; // 是否是观战者
	MmochatBattleRecord battle;

	public Mmochat_3_1S_Record() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_3_1);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		out.putInt(mapId);
		out.put(line);
		out.putInt(battle.getId());
		out.putUnsigned((short) battle.getTurn());
		if (isAudience) {
			out.put((byte) 1);
		} else {
			out.put((byte) 0);
		}
		out.put(myPos);
		out.put((byte) battle.getRoles().size());
		for (Entry<Byte, MmochatRoleRecord> item : battle.getRoles().entrySet()) {
			byte pos = item.getKey();
			MmochatRoleRecord role = item.getValue();
			out.putInt(role.getId());
			out.put((byte) pos);
			out.putUnsignedShort(role.getBmpType().getValue());
			out.putPrefixedString(role.getName(), 1);
			out.putUnsignedInt(role.getSmeValue());
			out.putInt(role.getTotalBlood());
			out.putInt(role.getCurPkBlood());
			out.putInt(role.getTotalSprit());
			out.putInt(role.getCurPkSprit());
			// 技能
			out.put((byte) 0);
			out.put((byte) 0);
			out.put((byte) 0);
		}
	}

	public void setMapId(int mapId) {
		this.mapId = mapId;
	}

	public void setLine(byte line) {
		this.line = line;
	}

	public void setBattle(MmochatBattleRecord battle) {
		this.battle = battle;
	}

	public void setMyPos(byte myPos) {
		this.myPos = myPos;
	}

	public void setPetPos(Byte petPos) {
		this.petPos = petPos;
	}

	public void setAudience(boolean isAudience) {
		this.isAudience = isAudience;
	}

}
